﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;

namespace 自动更新
{
    public partial class updatesever : Form
    {
        string _OpenPath;
        string _SavePath;
        XmlDocument update = new XmlDocument();
        public updatesever()
        {
            InitializeComponent();
        }

        private void BrowseButton_Click(object sender, EventArgs e)
        {
//            saveFileDialog1.AutoUpgradeEnabled = true;
            openFileDialog1.ShowDialog();
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            _OpenPath = openFileDialog1.FileName;
            FileTextBox.Text = Path.GetFileName(_OpenPath);
        }

        private void GenerateButton_Click(object sender, EventArgs e)
        {
            XmlElement NRoot;
            XmlNode xmlNode;
            xmlNode = update.CreateNode(XmlNodeType.XmlDeclaration, "", "");
            update.AppendChild(xmlNode);
            NRoot = update.CreateElement("UpdateInfo");
            update.AppendChild(NRoot);
            XmlElement updatefile;
            XmlText updatefiletext;
            updatefile = update.CreateElement("Name");
            updatefiletext = update.CreateTextNode(FileTextBox.Text);
            updatefile.AppendChild(updatefiletext);
            NRoot.AppendChild(updatefile);

            XmlElement updateversiondate;
            XmlText updateversiondatetext;
            updateversiondate = update.CreateElement("VersionDate");
            updateversiondatetext = update.CreateTextNode(VersionDateTextBox.Text);
            updateversiondate.AppendChild(updateversiondatetext);
            NRoot.AppendChild(updateversiondate);

            XmlElement updateversion;
            XmlText updateversiontext;
            updateversion = update.CreateElement("Version");
            updateversiontext = update.CreateTextNode(VersionTextBox.Text);
            updateversion.AppendChild(updateversiontext);
            NRoot.AppendChild(updateversion);

            XmlElement updateurl;
            XmlText updateurltext;
            updateurl = update.CreateElement("Url");
            updateurltext = update.CreateTextNode(SeverLocationText.Text);
            updateurl.AppendChild(updateurltext);
            NRoot.AppendChild(updateurl);

            XmlElement updatedescribe;
            XmlText updatedescribetext;
            updatedescribe = update.CreateElement("Describe");
            updatedescribetext = update.CreateTextNode(DescribeTextBox.Text);
            updatedescribe.AppendChild(updatedescribetext);
            NRoot.AppendChild(updatedescribe);

            saveFileDialog1.ShowDialog();



        }

        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            _SavePath = saveFileDialog1.FileName;
            update.Save(_SavePath);
            MessageBox.Show("保存xml成功，请上传到服务器", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

    }
}
